﻿using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using SubjectWorkShop.Core;

namespace SubjectWorkShop.Web.App_Code.HttpHandlers
{
    public class Background : IHttpHandler
    {
        #region IHttpHandler 成员

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            if (!string.IsNullOrEmpty(context.Request.QueryString["showGb"]) && context.Request.QueryString["showGb"] == "true")
            { 
                ShowBackground(context);
            }
            else
            {
                if (context.Request.Files.Count > 0)
                {
                    HttpPostedFile f = context.Request.Files[0];
                    string fname = f.FileName;
                }
            }



        }

        #endregion

        private void ShowBackground(HttpContext context)
        {
            string xmlpath = System.Web.Hosting.HostingEnvironment.MapPath(SubjectSettings.Instance.StorageLocation + @"Background.xml");
            XmlDocument doc = new XmlDocument();

            context.Response.Clear();
            context.Response.ContentType = "text/xml";

            try
            {
                doc.Load(xmlpath);
            }
            catch (XmlException ex)
            {
                throw new Exception("处理出错", ex);
            }
            doc.Save(context.Response.OutputStream);
            context.Response.End();
        }
    }
}
